package com.zt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zt.dao.Employeedao;
import com.zt.dao.Storedao;
import com.zt.service.EmployeeService;
import com.zt.utils.Query;
import org.example.systemset_pojo.Banner;
import org.example.systemset_pojo.Employee;
import org.example.systemset_pojo.Store;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmployeeServiceImpl extends ServiceImpl<Employeedao, Employee> implements EmployeeService {
    @Autowired
    private Employeedao employeedao;
    @Autowired
    private Storedao storedao;

    @Override
    public Page<Employee> selectpage(Query query) {
        Page<Employee> page=new Page<>(query.getPage(),query.getSize());
        QueryWrapper<Employee> wrapper=new QueryWrapper<>();
        wrapper.between(query.getStartTime()!=null&&query.getEndTime()!=null,"join_date",query.getStartTime(),query.getEndTime());
        employeedao.selectPage(page, wrapper);
        List<Employee> records = page.getRecords();
        if (records.size()>0){
            for (Employee b : records) {
                Integer id = b.getStoreId();
                Store store = storedao.selectById(id);
                if (store != null) {
                    b.setStoreName(store.getName());
                } else {
                    b.setStoreName(""); // 设置默认值
                }
            }
        }
        return page;
    }

    @Override
    public List<Store> glist() {
        return storedao.selectList(null);
    }
}
